﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace sampleTest
{
    class SplitFile
    {
        public static void SplitFileInTwo(string fileName) 
        {
            FileStream input = new FileStream(fileName, FileMode.Open);
            using (input)
            {
                byte[] buffer;
                if (input.Length % 2 == 1)
                {
                    buffer = new byte[input.Length / 2 + 1];
                }
                else 
                { 
                    buffer = new byte[input.Length/2];
                }
                for (int i = 1; i < 3; i++)
                {
                    FileStream outputFile = new FileStream("part"+i.ToString()+fileName, FileMode.Create);
                    using (outputFile) 
                    {
                        int read=input.Read(buffer, 0, buffer.Length);
                        outputFile.Write(buffer, 0, read);
                    }
                }
            }
        }

        static void Main(string[] args)
        {
            string fileName = "pesho.txt";
            SplitFileInTwo(fileName);
            
        }
    }
}
